package cn.tedu.csmall.stock.webapi.quartz;

import cn.tedu.csmall.stock.webapi.config.RabbitMQConfig;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

public class RabbitMQJob implements Job {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //向rabbitmq发送当前时间
        LocalDateTime now = LocalDateTime.now();
        //convertAndSend([交换机名称],[路由key的名称],[要发送的数据])
        //发送的消息数据，自动帮我们转成byte[]类型
        rabbitTemplate.convertAndSend(RabbitMQConfig.STOCK_EX,RabbitMQConfig.STOCK_ROUTE,now);
    }
}
